package com.knowif.backend.service;

import java.util.List;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.knowif.enumInfo.UserEnum;
import com.knowif.pojo.TUser;
import com.knowif.pojo.TUserExample;
import com.knowif.search.SearchCondition;
import com.knowif.service.User_service;
import com.knowif.system.model.RestBean;
import com.knowif.util.ExampleUtil;

/**
 * @author xingyao
 * @Description: 用户信息管理
 */
@Service
public class UserService {
	
	@Autowired
	private User_service user_service;
	
	public RestBean<?> selectTUser(SearchCondition searchCondition){
		if(searchCondition == null){
			return RestBean.buildError("请输入查找的信息");
		}
		try {
			TUserExample tUserExample = ExampleUtil.buildExample(new TUserExample(), searchCondition);
			tUserExample.createCriteria().andUserTypeEqualTo(UserEnum.USER.getNumber());
			List<TUser> tUsers = user_service.selectUser(tUserExample);
			PageInfo<TUser> pageInfo = new PageInfo<TUser>(tUsers);
			return RestBean.buildSuccess(pageInfo);
		} catch (Exception e) {
			return RestBean.buildError("系统错误，请稍后再试");
		}
	}
	
	
	/**
	 * @author: xingyao 
	 * @Description:  删除用户信息
	 * @param userId
	 * @return
	 */
	public RestBean<?> deleteTUser(Integer userId){
		TUser tUser = new TUser();
		tUser.setId(userId);
		return user_service.deleteUser(tUser);
	}
	
	/**
	 * @author: xingyao 
	 * @Description:  批量删除用户信息
	 * @param userIds
	 * @return
	 */
	public RestBean<?> deleteTUsers(List<Integer> userIds){
		return user_service.deleteUsers(userIds);
		
	}
}
